//
//  MeTableViewCell.m
//  项目A_百思不得姐
//
//  Created by wudongyang on 16/5/25.
//  Copyright © 2016年 wudongyang. All rights reserved.
//

#import "MeTableViewCell.h"
#import <AFNetworking.h>

static NSString *const indexID = @"cell";
@interface MeTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic, strong)UICollectionViewFlowLayout *myflowLayout;
@property(nonatomic, strong)UICollectionView *myCollectionView;
@property(nonatomic, strong)NSMutableArray *allArray;
@property(nonatomic, strong)BaseUIView *hViewOne;
@property(nonatomic, strong)BaseUIView *hViewTwo;
@property(nonatomic, strong)BaseUIView *hViewThree;
@property(nonatomic, strong)BaseUIView *hViewFour;
@property(nonatomic, strong)BaseUIView *sViewOne;
@property(nonatomic, strong)BaseUIView *sViewTwo;
@property(nonatomic, strong)BaseUIView *sViewThree;

@end
@implementation MeTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self carteSubViews];
        self.allArray = [NSMutableArray array];
        [self getData];
    }
    return self;
}
-(void)carteSubViews{
    self.myflowLayout  = [[UICollectionViewFlowLayout alloc] init];
    self.myCollectionView = [[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:self.myflowLayout];
    
    
    // item上下之间的距离
    self.myflowLayout.minimumLineSpacing = 15;
    self.myflowLayout.itemSize = CGSizeMake(90, 90);
    self.myflowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.myCollectionView.dk_backgroundColorPicker = DKColorPickerWithRGB(0xFFFFFF,0x343434);
//    self.myCollectionView.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.myCollectionView];
    self.myCollectionView.dataSource = self;
    self.myCollectionView.delegate = self;
    [self.myCollectionView registerClass:[MeCollectionViewCell class] forCellWithReuseIdentifier:indexID];
    // 装饰线
    self.hViewOne = [[BaseUIView alloc] init];
//    self.hViewOne.backgroundColor = DSRGBA(223, 223, 223, 1);
    [self.contentView addSubview:self.hViewOne];
    
    self.hViewTwo = [[BaseUIView alloc] init];
//    self.hViewTwo.backgroundColor = DSRGBA(223, 223, 223, 1);
    [self.contentView addSubview:self.hViewTwo];
    
    self.hViewThree = [[BaseUIView alloc] init];
//    self.hViewThree.backgroundColor = DSRGBA(223, 223, 223, 1);
    [self.contentView addSubview:self.hViewThree];
    
    self.hViewFour = [[BaseUIView alloc] init];
//    self.hViewFour.backgroundColor = DSRGBA(223, 223, 223, 1);
    [self.contentView addSubview:self.hViewFour];
    
    self.sViewOne = [[BaseUIView alloc] init];
//    self.sViewOne.backgroundColor = DSRGBA(223, 223, 223, 1);
    [self.contentView addSubview:self.sViewOne];
    
    self.sViewTwo = [[BaseUIView alloc] init];
//    self.sViewTwo.backgroundColor = DSRGBA(223, 223, 223, 1);
    [self.contentView addSubview:self.sViewTwo];
    
    self.sViewThree = [[BaseUIView alloc] init];
//    self.sViewThree.backgroundColor = DSRGBA(223, 223, 223, 1);
    [self.contentView addSubview:self.sViewThree];
}
-(void)getData{
    //GET请求
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://api.budejie.com/api/api_open.php?a=square&appname=bs0315&asid=986C8830-1671-4071-BB49-37A7E7F66615&c=topic&client=iphone&device=ios%20device&from=ios&jbk=0&mac=&market=&openudid=21c4a1f4b37d431985e8e05255fdfec2bcb43c5a&udid=&ver=4.1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        NSLog(@"%@",responseObject);
        NSMutableArray *array = [responseObject objectForKey:@"square_list"];
        for (NSDictionary *dic in array) {
            squareModel *sqModel = [[squareModel alloc] init];
            [sqModel setValuesForKeysWithDictionary:dic];
            [self.allArray addObject:sqModel];
        }
        [self.myCollectionView reloadData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
        
    }];
    
    
    
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.allArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    MeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:indexID forIndexPath:indexPath];
    squareModel *model = self.allArray[indexPath.row];
    cell.sqModel = model;
    return cell;

}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    squareModel *sqModel = self.allArray[indexPath.row];
    DSLog(@"%@的点击方法",sqModel.name);
    
    if (indexPath.item == 0) {
//        NSLog(@"审贴");
    }else if (indexPath.item == 1){
//        NSLog(@"排行榜");
    }else if (indexPath.item == 2){
//        NSLog(@"我的收藏");
        self.CollectBlock();
    }else if (indexPath.item == 3){
//        NSLog(@"随机穿越");
    }else if (indexPath.item == 4){
//        NSLog(@"意见反馈");
        self.YJBlock();
    }else if (indexPath.item == 5){
//        NSLog(@"搜索");
    }else if (indexPath.item == 6){
//        NSLog(@"流量充值");
        self.TrafficBlock();
    }else if (indexPath.item == 7){
//        NSLog(@"美女写真");
        self.GirlBlock();
    }else if (indexPath.item == 8){
//        NSLog(@"更多");
        self.TNBlock();
    }

}
-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.myCollectionView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    self.hViewOne.frame = CGRectMake(0, 0, self.contentView.frame.size.width, 1);
    self.hViewTwo.frame = CGRectMake(0, 97.5, self.contentView.frame.size.width, 1);
    self.hViewThree.frame = CGRectMake(0, 202.5, self.contentView.frame.size.width, 1);
    self.hViewFour.frame = CGRectMake(0, 307.5, self.contentView.frame.size.width, 1);
    self.sViewOne.frame = CGRectMake(97.5, 0, 1, self.contentView.frame.size.height);
    self.sViewTwo.frame = CGRectMake(206, 0, 1, self.contentView.frame.size.height);
    self.sViewThree.frame = CGRectMake(315, 0, 1, self.contentView.frame.size.height);

}


















@end
